<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('基础数据新增')" />
<style>
.layui-form {padding: 16px 84px 16px 25px;}
.layui-form-label{width:122px;padding-left:0}
.layui-input-block{margin-left:140px;}
.layui-form-radio{padding-right:0}
.getMore {top: 13px !important;right: 8px !important;line-height: initial;position: absolute;margin-top: -4px;}
</style>
</head>
<body class="no-skin">
<div class="main-container">
    <form class="layui-form" action="">
        <input type="hidden" th:each="fieldhide : ${fieldsHiddenList}" th:name="${fieldhide?.fields}" th:id="${fieldhide?.fields}" th:value="${fieldhide?.fieldContent}">
        <div class="layui-form-item" th:each="field : ${fieldsList}">
            <label class="layui-form-label"><font class="f_red" th:if="${#bools.isTrue(field?.fieldFrontRequired)}">*</font>[[${field.fieldName}]]：</label>
            <div class="layui-input-block">
                <input th:if="${field.fieldFrontType} eq 't_text'" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" autocomplete="off" th:onblur="${field?.fieldFrontRequired==true}? 'inputOnBlur(this)' : ''" th:readonly="${field?.fieldFrontEdit==false or (field?.fields=='vid' and field?.fieldContent != '')}? 'true' : 'false'" class="layui-input">
                <input th:if="${field.fieldFrontType} eq 't_decimal'" type="number" lay-verify="number" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" autocomplete="off" th:onblur="${field?.fieldFrontRequired==true}? 'inputOnBlur(this)' : ''" th:readonly="${field?.fieldFrontEdit==false}? 'true' : 'false'" class="layui-input">
                <input th:if="${field.fieldFrontType} eq 't_date'" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" autocomplete="off" readonly class="layui-input t_date">
	    		<input th:if="${field.fields} eq 'bdeletedtext'" type="checkbox" th:checked="${field?.fieldContent == '是'}" id="bdeletedtext" 
	    		lay-skin="switch" lay-filter="change" lay-text="是|否">
	    		<input th:if="${field.fields} eq 'bdefaulttext'" type="checkbox" th:checked="${field?.fieldContent == '是'}" id="bdefaulttext" 
	    		lay-skin="switch" lay-filter="change" lay-text="是|否">
	    		<input th:if="${field.fieldFrontType} eq 't_buttontext'" type="text" class="layui-input buttontext" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" readonly/>
				<i th:if="${field.fieldFrontType} eq 't_buttontext'" class="layui-icon layui-icon-more getMore" th:onclick="getMoreBase([[${field?.fieldFrontValue}]]);" th:getType="${field?.fields}"></i>
				<textarea th:if="${field.fieldFrontType} eq 't_textarea'" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" class="layui-textarea">[[${field.fieldContent}]]</textarea>
				<select th:if="${field.fieldFrontType} eq 't_dropdown'" type="text" th:id="${field?.fields}" th:name="${field?.fields}" autocomplete="off" class="layui-select" lay-search th:with="map=${@baseinfosimple.getDropdownData(field.fieldSearchType,field.fieldFrontSave,field.fieldFrontShow)}">
					<option></option>
					<option th:each="dict : ${map}" th:text="${dict.vname}" th:value="${dict.vid}" th:selected="(${#strings.isEmpty(field.fieldContent)} and ${dict.bdefaulttext eq '是'}) or ${dict.vid.toString() eq field.fieldContent.toString()} or ${dict.vname.toString() eq field.fieldContent.toString()}" th:data-vremark="${dict.vremark}"></option>
				</select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    /*<![CDATA[*/
    var ajaxResult = [[${ajaxResult}]];
    /*]]>*/
</script>
 <script type="text/javascript">
    layui.use(['table','form','layer','jquery'], function () {
        var $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table;
        if(ajaxResult.code==500) {
            $.modal.alert(ajaxResult.msg, modal_status.FAIL);
        };
      //监听开关动作
     	form.on('switch(change)', function(obj){
     		if(obj.elem.checked==true){
     			switch(obj.elem.id){
     			case 'bdeletedtext':
     				$("#bdeleted").val(1);
     				break
     			case 'bdefaulttext':
     				$("#bdefault").val(1);
     				break
     			}
        	}else{
        		switch(obj.elem.id){
     			case 'bdeletedtext':
     				$("#bdeleted").val(0);
     				break
     			case 'bdefaulttext':
     				$("#bdefault").val(0);
     				break
     			}
    	    }
        });
    })
    function getMoreBase(getType){
		var flag = true,
			mWidth=$(window).width()-200,
			mHeight=$(window).height()-100;
		switch(getType){
			case 'fhfs':
				var mTitle = '选择发货方式', mUrl = '/base/baseinfo/select?vtype=fhfs';
				break;
			case 'fyxm':
				var mTitle = '选择费用项目', mUrl = '/base/baseinfo/select?vtype=fyxm';
				break;
			case 'userinfo':
				var mTitle = '选择员工', mUrl = '/system/user/userselect?pagetype=radio';
				break;
			default:
				flag=false;
				layer.msg('无该选择');
				break;
		}
	    if(flag){
		    $.modal.open(mTitle, mUrl, mWidth, mHeight, function(index){
		        var res = window["layui-layer-iframe" + index].callbackdata();
		        if(res=="none"){//没有选中时
	            	layer.msg("请选择！");
	            }else{
	            	var fieldsList;//目标字段及数据源字段 对象
	            	switch(getType){
	            		case 'fhfs':	//发货方式
	            			fieldsList =  {'pguid':'guid','pguidName':'vname'};
	            			break;
	            		case 'fyxm':	//费用项目
	            			fieldsList =  {'pguid':'guid','pguidName':'vname'};
	            			break;
	            		case 'userinfo':	
	            			fieldsList =  {'vname':'userName','vid':'userId'};
	            			break;
	            		default:
	            			layer.msg('填充数据未处理！');
	            			break;
	            	}
	        		$.each(fieldsList, function(i, v){
	        			$("#"+i).val(res[v]);
	        			$("#"+i).css('border','1px solid #e6e6e6');
	        		});
	    	        layer.close(index);
	            }
		    });
	    }
	}
    function setVid(obj){
        $(".vid").val($(obj).val());
    }
 </script>
</body>
</html>